package com.ruoyi.web.controller.workSafetyStandardization.rule;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workSafetyStandardization.domain.BasicStandard;
import com.ruoyi.workSafetyStandardization.service.IBasicStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 达标基本条件Controller
 *
 * @author hcc
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/secure/securerule/BasicStandard")
public class BasicStandardController extends BaseController
{
    @Autowired
    private IBasicStandardService basicStandardService;

    /**
     * 查询达标基本条件列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:BasicStandard:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicStandard basicStandard,@Param("pageSize") String pageSize,@Param("pageNum") String pageNum)
    {
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        List<BasicStandard> list = basicStandardService.selectBasicStandardList(basicStandard);
        return getDataTable(list);
    }

    /**
     * 导出达标基本条件列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:BasicStandard:export')")
    @Log(title = "达标基本条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicStandard basicStandard)
    {
        List<BasicStandard> list = basicStandardService.selectBasicStandardList(basicStandard);
        ExcelUtil<BasicStandard> util = new ExcelUtil<BasicStandard>(BasicStandard.class);
        util.exportExcel(response, list, "达标基本条件数据");
    }

    /**
     * 获取达标基本条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:BasicStandard:query')")
    @GetMapping(value = "/{basicStandardId}")
    public AjaxResult getInfo(@PathVariable("basicStandardId") String basicStandardId)
    {
        return success(basicStandardService.selectBasicStandardByBasicStandardId(basicStandardId));
    }

    /**
     * 新增达标基本条件
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:BasicStandard:add')")
    @Log(title = "达标基本条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicStandard basicStandard)
    {
        basicStandard.setBasicStandardId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(basicStandardService.insertBasicStandard(basicStandard));
    }

    /**
     * 修改达标基本条件
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:BasicStandard:edit')")
    @Log(title = "达标基本条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicStandard basicStandard)
    {
        return toAjax(basicStandardService.updateBasicStandard(basicStandard));
    }

    /**
     * 删除达标基本条件
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:BasicStandard:remove')")
    @Log(title = "达标基本条件", businessType = BusinessType.DELETE)
	@GetMapping("/delete")
    public AjaxResult remove(@Param("basicStandardId") String basicStandardId)
    {
        String[] basicStandardIds={basicStandardId};
        return toAjax(basicStandardService.deleteBasicStandardByBasicStandardIds(basicStandardIds));
    }
}
